﻿// Dlg1.cpp: 实现文件
//

#include"stdafx.h"
#include "ArcFaceDemo.h"
#include "Dlg1.h"
#include "afxdialogex.h"
#include "ArcFaceDemoDlg.h"
#include"Dlg2.h"


// CDlg1 对话框

IMPLEMENT_DYNAMIC(CDlg1, CDialogEx)

CDlg1::CDlg1(CWnd* pParent /*=nullptr*/)
	: CDialogEx(StuStat_1, pParent)
{
	
	
}

CDlg1::~CDlg1()
{
}

void CDlg1::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, StuList, stuList);
}


BEGIN_MESSAGE_MAP(CDlg1, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CDlg1::OnBnClickedButton1)
	ON_NOTIFY(NM_CLICK, StuList, &CDlg1::OnClickStulist)
	ON_BN_CLICKED(IDC_BUTTON2, &CDlg1::OnClickedRemarkButton)
END_MESSAGE_MAP()


// CDlg1 消息处理程序



void CDlg1::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	statChange(ColIndex);
}


BOOL CDlg1::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	//初始化表
	CString str[] = { TEXT("姓名"),TEXT("人脸ID") ,TEXT("学号") ,TEXT("备注")};
	for (int i = 0; i < 4; i++)
	{
		//设置表头
		stuList.InsertColumn(i, str[i]);
		stuList.SetColumnWidth(i, 100);
	}
	//初始化按钮
	GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);

	//初始化remarkdlg
	remarkdlg = new CRemarkDlg;
	remarkdlg->ShowWindow(false);
	
	

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}




void CDlg1::OnClickStulist(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	this->ColIndex = pNMItemActivate->iItem;
	GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	*pResult = 0;
}

void CDlg1::insertStu(CString name,CString FaceID,CString StuID) 
{
	(this->stuList).InsertItem(stuList.GetItemCount(), name);
	stuList.SetItemText(stuList.GetItemCount() - 1,1, FaceID);
	stuList.SetItemText(stuList.GetItemCount() - 1, 2, StuID);
	stuList.SetItemText(stuList.GetItemCount() - 1, 3, TEXT(" "));
}

void CDlg1::OnClickedRemarkButton()
{
	// TODO: 在此添加控件通知处理程序代码
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	remarkdlg->ShowWindow(true);
	remarkdlg->DoModal();
	if(remarkdlg->ifUPDATE)
	{
		stuList.SetItemText(ColIndex, 3, remarkdlg->getRemark());
	}
	remarkdlg->ifUPDATE = FALSE;
}

int CDlg1::SearchByPicID(CString FaceID)
{
	int colIndforSearch = -1;
	for (int i = 0; i < stuList.GetItemCount(); i++)
	{
		if ((CString)stuList.GetItemText(i, 2) == FaceID) { colIndforSearch = i; break; }
		else {}
	}
	return colIndforSearch;
}

void CDlg1::statChange(int ColIndex)
{
	if (ColIndex < 0) { return; }
	CDlg2* tmpdlg = (CDlg2*)(((CArcFaceDemoDlg*)AfxGetMainWnd())->GetTabSheet()->getDialogPage(1));
	(tmpdlg->getList())->InsertItem(tmpdlg->getList()->GetItemCount(), (stuList.GetItemText(ColIndex, 0)));
	for (int i = 1; i <= 3; i++)
	{
		(tmpdlg->getList())->SetItemText(tmpdlg->getList()->GetItemCount() - 1, i, (stuList.GetItemText(ColIndex, i)));
	}
	stuList.DeleteItem(ColIndex);
	this->GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	
	ColIndex = -1;
}